package com.easy.generator;

/**
 * @author easy
 * @date 2025年07月05日 08:41
 */

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;

public class YMLGenerator {
    private static final String FILE_NAME="application.yml";
    private static final String CLASS_TEMPLATE =
            "server:\n" +
                    "    port: "+Easy.SERVER_PORT+"\n" +
                    "\n" +
                    "spring:\n" +
                    "    datasource:\n" +
                    "        driver-class-name: com.mysql.cj.jdbc.Driver\n" +
                    "        url: jdbc:mysql://127.0.0.1:3306/"+Easy.MYSQL_DATABASE_NAME+"?serverTimezone=GMT%%2b8\n" +
                    "        username: root\n" +
                    "        password: "+Easy.MYSQL_PASSWORD+"\n" +
                    "    servlet:\n" +
                    "        multipart:\n" +
                    "            max-file-size: 100MB\n" +
                    "            max-request-size: 100MB";

    public static void generate() throws IOException {
        String content = String.format(CLASS_TEMPLATE, LocalDate.now());
        File outputFile = new File(Easy.PROJECT_ABSOLUTE_URL+Easy.RESOURCE_DIR+"/"+FILE_NAME);
        try (FileWriter writer = new FileWriter(outputFile)) {
            writer.write(content);
        }
    }

}
